<?php
set_time_limit(0);
ini_set('memory_limit', '-1');

require_once 'asterisk.class.php';

$asterisk   = new asterisk('212.72.155.175', 5038, 'admin', 'elastixsudo', 20000);

$db         = mysql_connect('localhost', 'root', 'Gl-1114');
mysql_select_db('autoinformator', $db);

$log = time()."---call-OK\n";
file_put_contents("logs/callsTime.txt", $log, FILE_APPEND);

$result = mysql_query("SELECT   `request_detail_id`,
								`phone`,
								`expiration_type`,
								SUBSTRING_INDEX(`money`,'.',1), 
								SUBSTRING_INDEX(`money`,'.',-1),
								wait_time
                        FROM 	`scheduled_calls`
                        WHERE	`scheduled_calls`.`datetime` = $argv[1]");

while ($row = mysql_fetch_array($result)) {
    $array[]=$row;
}

foreach ($array as &$value) {
     
   $asterisk->makeCall($value[0], $value[1], $value[2], $value[3], $value[4], $value[5]);
   sleep(1);
    
}

